import config from "/src/config/global.js";
import Request from "./AxiosRequest.js"

class Common {
	constructor() {
		this.apiUrl = config.apiUrl;
		this.errorResult = {
			data: false,
			code: -1,
			msg: "拒绝发起请求！"
		}
	}
	
	get token() {
		return localStorage.getItem("taiva_iot_token");
	}
	
	/* 发起请求 */
	initiateRequest(url = "" , data = {}) {
		return new Promise((resolve , reject) => {
			Request.post(url , data).then(res => {
				if(res.hasOwnProperty("data")) {
					resolve(res);
				} else {
					reject(res)
				}
			}).catch(e => {
				reject(e);
			})
		});
	}
	
	/* 拒绝发起请求 */
	refuseRequest() {
		return new Promise((resolve, reject) => {
			resolve(this.errorResult)
		})
	}
}

export default Common